﻿@using Dignite.Abp.AspNetCore.Mvc.UI.Theme.Pure
@using Dignite.Abp.AspNetCore.Mvc.UI.Theme.Pure.Bundling
@using Dignite.Abp.AspNetCore.Mvc.UI.Theme.Pure.Themes.Pure.Components.BreadCrumbs
@using Dignite.Abp.AspNetCore.Mvc.UI.Theme.Pure.Themes.Pure.Components.Footer
@using Dignite.Abp.AspNetCore.Mvc.UI.Theme.Pure.Themes.Pure.Components.MainNavbar
@using Dignite.Abp.AspNetCore.Mvc.UI.Theme.Pure.Themes.Pure.Components.MobileNavbar
@using Dignite.Abp.AspNetCore.Mvc.UI.Theme.Pure.Themes.Pure.Components.OffcanvasNavbar
@using Dignite.Abp.AspNetCore.Mvc.UI.Theme.Pure.Themes.Pure.Components.PageAlerts
@using Microsoft.Extensions.DependencyInjection
@using SeoTags
@using Volo.Abp.AspNetCore.Mvc.UI.Components.LayoutHook
@using Volo.Abp.AspNetCore.Mvc.UI.Layout
@using Volo.Abp.AspNetCore.Mvc.UI.Theming
@using Volo.Abp.AspNetCore.Mvc.UI.Widgets.Components.WidgetScripts
@using Volo.Abp.AspNetCore.Mvc.UI.Widgets.Components.WidgetStyles
@using Volo.Abp.Localization
@using Volo.Abp.Ui.Branding
@using Volo.Abp.Ui.LayoutHooks
@inject IBrandingProvider BrandingProvider
@inject IPageLayout PageLayout
@{
    Layout = null;
    var containerClass = ViewBag.FluidLayout == true ? "container-fluid" : "container"; //TODO: Better and type-safe options

    //
    var seoInfo = Context.RequestServices.GetRequiredService<SeoInfo>();

    //
    var rtl = CultureHelper.IsRtl ? "rtl" : string.Empty;
}

<!DOCTYPE html>

<html lang="@CultureInfo.CurrentUICulture.Name" dir="@rtl">
<head>
    @await Component.InvokeLayoutHookAsync(LayoutHooks.Head.First, StandardLayouts.Application)

    @if (!seoInfo.MetaLink.PageTitle.IsNullOrWhiteSpace())
    {
        @Html.SeoTags()
    }
    else
    {
        var pageTitle = ViewBag.Title == null ? PageLayout.Content.Title : ViewBag.Title;
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>@(string.Format(seoInfo.MetaLink.TitleFormat, pageTitle, BrandingProvider.AppName))</title>
    }

    <script src="~/themes/pure/color-mode-switch.js"></script>

    <abp-style-bundle name="@PureThemeBundles.Styles.Global" />
    @await Component.InvokeAsync(typeof(WidgetStylesViewComponent))
    @await RenderSectionAsync("styles", false)

    <script type="text/javascript">
        var dignite = dignite || {};
        dignite.brand = dignite.brand || {};
        dignite.brand.appName='@BrandingProvider.AppName';
        dignite.brand.logoUrl='@BrandingProvider.LogoUrl';
        dignite.brand.logoReverseUrl='@BrandingProvider.LogoReverseUrl';
    </script>

    @await Component.InvokeLayoutHookAsync(LayoutHooks.Head.Last, StandardLayouts.Application)
</head>
<body class="abp-application-layout @rtl">
    @await Component.InvokeLayoutHookAsync(LayoutHooks.Body.First, StandardLayouts.Application)

    @(await Component.InvokeAsync<MainNavbarViewComponent>())
    <!-- Offcanvas Navbar -->
    <nav class="offcanvas offcanvas-start" tabindex="-1" aria-labelledby="mainOffcanvasNavbarLabel" id="main-offcanvas-navbar">
        @(await Component.InvokeAsync<MainOffcanvasNavbarViewComponent>())
    </nav>
    @(await Component.InvokeAsync<MobileNavbarViewComponent>())

    <div class="@containerClass">
        <!-- page content toolbar -->
        <div id="AbpContentToolbar" class="d-flex align-items-center sticky-top px-2 backdrop-blur content-toolbar">
            @(await Component.InvokeAsync<BreadCrumbsViewComponent>())
            @await RenderSectionAsync("content_toolbar", false)
        </div>

        @await Component.InvokeLayoutHookAsync(LayoutHooks.PageContent.First, StandardLayouts.Application)
        @(await Component.InvokeAsync<PageAlertsViewComponent>())
        @RenderBody()
        @await Component.InvokeLayoutHookAsync(LayoutHooks.PageContent.Last, StandardLayouts.Application)
    </div>
    
    @(await Component.InvokeAsync<FooterViewComponent>())

    <abp-script-bundle name="@PureThemeBundles.Scripts.Global" />

    <script src="~/Abp/ApplicationLocalizationScript?cultureName=@CultureInfo.CurrentUICulture.Name"></script>
    <script src="~/Abp/ApplicationConfigurationScript"></script>
    <script src="~/Abp/ServiceProxyScript"></script>

    @await Component.InvokeAsync(typeof(WidgetScriptsViewComponent))

    @await RenderSectionAsync("scripts", false)

    @await Component.InvokeLayoutHookAsync(LayoutHooks.Body.Last, StandardLayouts.Application)
</body>
</html>
